﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.Data;
using System.ComponentModel;

namespace 工具
{
    public class GetObjectInfo
    {
        public void GetPros()
        {
            TestClass testClass = new TestClass{Name="张三",Description="这是描述",Age=23 };
            Type type = testClass.GetType();
            DataTable dataTable = new DataTable();
            dataTable.Columns.Add("字段名");
            dataTable.Columns.Add("字段值");
            dataTable.Columns.Add("描述");
           
            foreach (var property in type.GetProperties())
            {
                DataRow dataRow = dataTable.NewRow();
                dataRow["字段名"] =property.Name;
                dataRow["字段值"] =property.GetValue(testClass,null);
                // 获取属性的特性
                var des = property.GetCustomAttribute<ProDescriptAttribute>();
                dataRow["描述"] = des.Value;
                dataTable.Rows.Add(dataRow);
            }
           
        }
        
        
    }
    public class TestClass
    {
        [ProDescript("名称")]
        public string Name { get; set; }
        [ProDescript("描述")]
        public string Description { get; set; }
        [ProDescript("年纪")]
        public int Age { get; set; }
    }
   
}
